package cn.edu.sdjzu.xg2121.service;

import cn.edu.sdjzu.xg2121.dao.UniversityDao;
import cn.edu.sdjzu.xg2121.domain.University;
import cn.edu.sdjzu.xg2121.exception.BysjException;
import cn.edu.sdjzu.xg2121.util.CommonDao;
import cn.edu.sdjzu.xg2121.util.Condition;
import cn.edu.sdjzu.xg2121.util.JdbcHelper;
import cn.edu.sdjzu.xg2121.util.Pagination;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

public class UniversityService {
    private static final UniversityDao universityDao = UniversityDao.getInstance();
    private static final UniversityService universityService = new UniversityService();
    private UniversityService(){
    }
    public static UniversityService getInstance(){
        return universityService;
    }
    public String update(University university)throws SQLException {
        return universityDao.update(university);
    }
    public boolean delete(Integer id) throws SQLException {
        University university = UniversityService.getInstance().find(id);
        int count =SchoolService.getInstance().count(university);
        if(count==0){
            return universityDao.delete(id);
        }
        else {
            throw new BysjException(university.getDescription()+"学校仍然有学院存在");
        }
    }
    public University find(Integer id) throws SQLException {
        return universityDao.find(id);
    }
    public Collection<University> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {
        return UniversityDao.getInstance().findAll(conditionList, pagination);
    }

}
